package com.example.springboot.controller;

import com.example.springboot.common.OBJ;
import com.example.springboot.common.Result;
import com.example.springboot.service.BlockedWordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/blockedWord")
public class BlockedWordController {

    @Autowired
    private BlockedWordService blockedWordService;

    @PostMapping("/add")
    public Result addBlockedWord(@RequestBody BlockedWord blockedWord) {
        blockedWordService.addBlockedWord(blockedWord);
        return Result.success("添加成功");
    }

    @PutMapping("/update")
    public Result updateBlockedWord(@RequestBody BlockedWord blockedWord) {
        blockedWordService.updateBlockedWord(blockedWord);
        return Result.success("更新成功");
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteBlockedWordById(@PathVariable int id) {
        blockedWordService.deleteBlockedWordById(id);
        return Result.success("删除成功");
    }

    @PostMapping("/deleteList")
    public Result deleteBlockedWords(@RequestBody List<BlockedWord> blockedWords) {
        blockedWordService.deleteBlockedWords(blockedWords);
        return Result.success("删除成功！");
    }


    @PostMapping("/getByManyConditionInPage")
    public Result getByManyConditionInPage(@RequestBody OBJ obj) {
        return Result.success(blockedWordService.getByManyConditionInPage(obj.getBlockedWord(), obj.getCurrentPage(), obj.getPageSize()));
    }

    @PostMapping("/getAll")
    public Result getAllBlockedWords() {
        return Result.success(blockedWordService.getAllBlockedWords());
    }

}
